﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
      <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
    <link href="../assets/css/bootstrap.css" rel="stylesheet" />
    <link href="../assets/css/font-awesome.css" rel="stylesheet" />
    <link href="../assets/css/custom-styles.css" rel="stylesheet" />
    <link href="../assets/css/dataTables.bootstrap.css" rel="stylesheet" />
</head>
<body>
    <div id="wrapper">
        <div id="page-wrapper">
            <div id="page-inner">
			 <div class="row">
                    <div class="col-md-12">
                        <h1 class="page-header">
                            <i class="fa fa-user">&nbsp;</i>文章管理 <small>文章列表</small>
                        </h1>
                    </div>
                </div> 
            <div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             <button class="btn btn-success btn-lg" data-toggle="modal" data-target="">
                              	<a href="articleSave.html" style="color:white;">发布文章</a>
                            </button>
                        </div>
                        <!-- 弹出层(添加/编辑) -->
                        <div class="modal fade" id="saveModal" tabindex="-1" role="dialog" aria-labelledby="saveModalLabel" aria-hidden="true">
                                <div class="modal-dialog"  style="width:648px;">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                            <h4 class="modal-title" id="saveModalLabel" style="font-weight: bolder;">发布/修改文章</h4>
                                        </div>
                                        <div class="modal-body">
                                            <div class="form-group input-group">
	                                            <span class="input-group-addon">文章标题<font style="color:red;margin-left:5px;">*</font></span>
	                                            <input type="text" id="id" hidden="hidden">
	                                            <input type="text" id="title" class="form-control" placeholder="请输入文章标题" maxlength="50">
	                                        </div>
	                                        <div class="form-group input-group">
	                                            <span class="input-group-addon">作&nbsp;&nbsp;者<font style="color:red;margin-left:5px;">*</font></span>
	                                            <input type="text" id="author" class="form-control" placeholder="请输入作者" maxlength="50">
	                                        </div>
	                                        <div class="form-group input-group">
	                                            <span class="input-group-addon">文章类型<font style="color:red;margin-left:5px;">*</font></span>
	                                            <select class="form-control" id="menuid">
	                                            	
	                                            </select>
	                                        </div>
	                                        <div class="form-group input-group">
	                                            <span class="input-group-addon">文章来源<font style="color:red;margin-left:5px;">*</font></span>
	                                            <input type="text" id="source" class="form-control" placeholder="请输入文章来源" maxlength="10">
	                                        </div>
	                                        <div class="form-group input-group">
	                                            <span class="input-group-addon">文章内容<font style="color:red;margin-left:5px;">*</font></span>
	                                            <input type="text" id="content" class="form-control" placeholder="请输入文章来源" maxlength="10">
	                                            
	                                        </div>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                            <button type="button" class="btn btn-primary" onclick="save()">保存</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                         <!-- 弹出层（删除） -->
                         <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" data-id="" aria-labelledby="myModalLabel" aria-hidden="true">
						    <div class="modal-dialog">
						        <div class="modal-content">
						            <div class="modal-body">
						            	<input tyle="text" id="delid" value="" hidden="hidden">
						                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						                	你确认要删除么？
						            </div>
						            <div class="modal-footer">
						                <button type="button" class="btn btn-primary" id="deleteid" onclick="doDel()">确认</button>
						                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						            </div>
						        </div>
						    </div>
						</div>
						<!-- 弹出层（审核） -->
                         <div class="modal fade" id="auditModal" tabindex="-1" role="dialog" data-id="" aria-labelledby="myModalLabel" aria-hidden="true" style="text-align:center;">
						    <div class="modal-dialog">
						        <div class="modal-content">
						            <div class="modal-body">
						            	<input tyle="text" id="auditid" value="" hidden="hidden">
						                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						                	确定审核该用户？&nbsp;&nbsp;&nbsp;
						                <button class='btn btn-success btn-sm' onclick="auditUser(true)">审核通过</button>
						                <button class='btn btn-warning btn-sm' onclick="auditUser(false)">审核不通过</button>
						            </div>
						        </div>
						    </div>
						</div>
						<!-- 数据table -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example" >
                                    <thead>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
            </div>
    <script src="../assets/js/jquery-1.10.2.js"></script>
    <script src="../assets/js/bootstrap.min.js"></script>
    <script src="../assets/js/jquery.metisMenu.js"></script>
    <script src="../assets/js/dataTables/jquery.dataTables.min.js"></script>
    <script src="../assets/js/dataTables/dataTables.bootstrap4.js"></script>
    <script src="../js/user.js"></script>
        <script>
            $(document).ready(function () {
            	$('#dataTables-example').dataTable({  
                    "bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示  
                    "bServerSide" : true, //是否启动服务器端数据导入  
                    "bStateSave" : true, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态  
                    "bJQueryUI" : true, //是否使用 jQury的UI theme  
//                    "sScrollY" : 450, //DataTables的高  
//                    "sScrollX" : 820, //DataTables的宽  
                    "aLengthMenu" : [10,20, 50, 100], //更改显示记录数选项  
                    "iDisplayLength" : 10, //默认显示的记录数  
                    "bAutoWidth" : true, //是否自适应宽度  
                    "bScrollInfinite" : true, //是否启动初始化滚动条  
                    "bScrollCollapse" : true, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变  
                    "bPaginate" : true, //是否显示（应用）分页器  
                    "sInfo" : true, //是否显示页脚信息，DataTables插件左下角显示记录数  
                    "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页  
                    "bSort" : false, //是否启动各个字段的排序功能  
                    "aaSorting" : [[1, "asc"]], //默认的排序方式，第2列，升序排列  
                    "bFilter" : true, //是否启动过滤、搜索功能  
                    "serverSide": false,//打开后台分页
                    "paging": true,
                    "aoColumns" : [{
                        "mDataProp" : "id",  
                        "sTitle" : "序号",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": false,
                        "width":"5%",
                    }, {  
                        "mDataProp" : "account",  
                        "sTitle" : "用户名",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": false,
                        "width":"10%",
                    }, {  
                        "mDataProp" : "name",  
                        "sTitle" : "姓名",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": false,
                        "width":"10%",
                    },{  
                        "mDataProp" : "phone",  
                        "sTitle" : "联系电话",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": false,
                        "width":"10%",
                    },{  
                        "mDataProp" : "enterprisename",  
                        "sTitle" : "所属企业",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": false,
                        "width":"10%",
                    }, {  
                        "mDataProp" : "typename",  
                        "sTitle" : "用户类型",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": true,
                        "width":"10%",
                    },{  
                        "mDataProp" : "rolename",  
                        "sTitle" : "角色名称",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": true,
                        "width":"10%",
                    },{  
                        "mDataProp" : "auditName",  
                        "sTitle" : "审核状态",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": true,
                        "width":"7%",
                    },{
                        "mDataProp" : "updatetime",  
                        "sTitle" : "操作时间",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": true,
                        "width":"12%",
                    }, {  
                        "mDataProp" : "",  
                        "sTitle" : "操作",  
                        "sDefaultContent" : "",  
                        "sClass" : "center",
                        "orderable": false,
                        "width":"15%",
                    }],
                    "oLanguage": { //国际化配置  
            			        "sProcessing" : "正在获取数据，请稍后...",
            			        "sLengthMenu" : "<font style='color:black;font-size:16px;font-weight:bold;'>每页显示 _MENU_ 条</font>",    
            			        "sZeroRecords" : "没有您要搜索的内容",    
            			        "sInfo" : "<font style='color:black;font-size:16px;font-weight:bold;'>从 _START_ 到  _END_ 条记录 总记录数为 _TOTAL_ 条</font>",    
            			        "sInfoEmpty" : "没有记录",
            			        "sInfoFiltered" : "(全部记录数 _MAX_ 条)",    
            			        "sInfoPostFix" : "",    
            			        "sSearch" : "<font style='color:black;font-size:16px;font-weight:bold;'>搜索:</font>",    
            			        "sUrl" : "",
            			        "oPaginate": {
        						         "sFirst" : "第一页",    
        						         "sPrevious" : "上一页",    
        						         "sNext" : "下一页",    
        						         "sLast" : "最后一页"    
          					      },
            		        	  "aria": {
            		        	        "sortAscending":  ": activate to sort column ascending",
            		        	        "sortDescending": ": activate to sort column descending"
            		        	  }
                    },  
                              
                    "fnRowCallback" : function(nRow, aData, iDisplayIndex) {  
                        /* 用来改写用户权限的 */
                        var editHtml="<button class='btn btn-success btn-sm' data-toggle='modal' data-target='#saveModal' style='background-color:#7D7DFF;font-weight:bold;' data-id='"+aData.id+"'>编辑</button>";
                        var delHtml="&nbsp;<button class='btn btn-warning btn-sm' data-toggle='modal' data-target='#deleteModal' style='font-weight:bold;'  data-id='"+aData.id+"'>删除</button>";
                        var auditHtml = "&nbsp;<button class='btn btn-info btn-sm' data-toggle='modal' data-target='#auditModal' style='font-weight:bold;' data-id='"+aData.id+"'>审核</button>";
                        $('td:eq(0)', nRow).html(iDisplayIndex+1);
                        $('td:eq(9)', nRow).html(editHtml+delHtml+auditHtml);
                        return nRow;
                    },
                      
                    "sAjaxSource" : req_user+"/user/queryUser",
                        //服务器端，数据回调处理  
                    "fnServerData" : function(sSource, aDataSet, fnCallback) {  
                    	aDataSet.push({"name":"operateid","value":getAdmCookie().id});
                        $.ajax({
                            "dataType" : 'json',  
                            "type" : "POST",  
                            "url" : sSource,  
                            "data" : aDataSet,  
                            "success" : fnCallback  
                        });  
                    }  
                });
            });
            
          //点击删除按钮时，给弹出层绑定对应的id值
           $('#deleteModal').on('show.bs.modal', function (event) {
               var button = $(event.relatedTarget); // 触发事件的按钮
               var id = button.data('id'); // 解析出data-id内容
               $('#delid').val(id);
           });
          
          //点击审核按钮时，给弹出层绑定对应的id值
          $('#auditModal').on('show.bs.modal', function (event) {
              var button = $(event.relatedTarget); // 触发事件的按钮
              var id = button.data('id'); // 解析出data-id内容
              $('#auditid').val(id);
          });
          
            //点击编辑按钮时，给弹出层绑定对应的id值
           	$('#saveModal').on('show.bs.modal', function (event) {
                   var button = $(event.relatedTarget); // 触发事件的按钮
                   var id = button.data('id'); // 解析出data-id内容
                   //初始化角色下拉框
                   var url = req_user+"/role/queryRole";
                   var data = req_ajax(url,{});
                   if(data){
                	   $("#roleid").empty();
                	   for(var i=0;i<data.data.length;i++){
                		   $("#roleid").append("<option value='"+data.data[i].id+"'>"+data.data[i].name+"</option>");
                	   }
                   }
                   
                   if(id){
                	   $('#roleid').val(id);
                	   var reqURL = req_user+"/user/queryUser";
                	   var param = {};
                	   param["id"] = id;
                   	   var data = req_ajax(reqURL,param);
                	   if(data){
                		   $("#id").val(data.data[0].id);
                		   $("#account").val(data.data[0].account);
                		   $("#password").val(data.data[0].password);
                		   $("#repassword").val(data.data[0].password);
                		   $("#name").val(data.data[0].name);
                		   $("#phone").val(data.data[0].phone);
                		   $("#roleid").val(data.data[0].roleid);
                	   }
                   }else{
                	   cleanShowModel();
                   }
               });
            
            //删除操作
            function doDel(){
            	var id = $('#delid').val();
            	var paramjson = {};
            	paramjson["id"] = id;
            	var reqURL = req_user+"/user/deleteUser";
            	var data = req_ajax(reqURL,paramjson);
            	if(data.flag == 1){
            		window.location.reload();
            	}
            }
            
            //审核操作
            function auditUser(isaudit){
            	var reqURL = req_user+"/user/updateUser";
            	var id = $('#auditid').val();
            	var paramjson = {};
            	paramjson["id"] = id;
            	if(isaudit){
            		paramjson["auditstate"] = 1;
            	}else{
            		paramjson["auditstate"] = 0;
            	}
            	var data = req_ajax(reqURL,paramjson);
            	if(data){
            		if(data.flag == 1){
            			window.location.reload();
            		}
            	}else{
            		alert("系统出错，请联系管理员！");
            	}
            }
            
            //保存按钮点击事件
            function save(){
            	var param = {};
            	param["id"]=$("#id").val();
            	param["account"]=$("#account").val();
            	param["password"]=$("#password").val();
            	param["repassword"]=$("#repassword").val();
            	param["name"]=$("#name").val();
            	param["phone"]=$("#phone").val();
            	param["roleid"]=$("#roleid").val();
            	param["type"]="admin";
            	var url = req_user+"/user/saveUser";
            	var data = req_ajax(url,param);
            	if(data.flag == 1){
            		window.location.reload();
            	}
            }
            
            //清空弹出层内所有控件内容
            function cleanShowModel(){
               $("#id").val("");
     		   $("#account").val("");
     		   $("#password").val("");
     		   $("#repassword").val("");
     		   $("#name").val("");
     		   $("#phone").val("");
     		   $("#roleid").val("");
            }
    </script>
    <script src="../assets/js/custom-scripts.js"></script>
    
	<script src="../../common/cookie.js"></script>
	<script src="../js/include.js"></script>
	<script src="../assets/js/jquery.cookie.js"></script>
</body>
</html>
